package com.itheima.Controller;

import com.itheima.common.entity.Result;
import com.itheima.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 体检预约接口
 */
@RestController
@RequestMapping("")
@Slf4j
public class OrderControler {

    @Autowired
    private com.itheima.service.OrderService orderService;

    /**
     * 根据预约id查询预约信息
     *
     * @param id
     * @return
     */
    @GetMapping("/order/findById")
    public Result findById(Integer id) {
        log.info("根据预约id查询预约信息：{}", id);
        try {
            return new Result(true, "查询成功", orderService.findById(id));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询失败");
        }
    }

    /**
     * 体检预约
     *
     * @param orderDTO
     * @return
     */
    @PostMapping("/order/submitOrder")
    public Result submitOrder(@RequestBody OrderDTO orderDTO) {
        log.info("体检预约：{}", orderDTO);
        try {
            orderService.submitOrder(orderDTO);
            return new Result(true, "预约成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "预约失败");
        }
    }

    /**
     * 发送预约验证码
     *
     * @param telephone
     * @return
     */
    @PostMapping("/validatecode/send4Order")
    public Result sendValidateCode4Order(String telephone) {
        log.info("发送预约验证码,手机号：{}", telephone);
        try {
            orderService.sendValidateCode4Order(telephone);
            return new Result(true, "发送成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "发送失败");
        }
    }
}
